
package cnd;

/**
 * SearchController is the layer that communicates between the Controller
 * and the Search and SearchResults classes.
 * @author Marten Jacobs
 * @version 0.1
 */
class SearchController {
    private Controller controller;
    private SearchResults searchResults;
    private SearchResultTableModel searchResultTableModel;
    /**
     * @param controller
     * The controller to communicate with
     */
    public SearchController(Controller controller){
        this.controller = controller;
    }
    /**
     * This initiates the searchResultsTableModel so the ResultsTable in the
     * MainWindow will already show the column headers before a search is
     * executed.
     */
    public void init(){
        searchResults = new SearchResults(this);
        searchResultTableModel = new SearchResultTableModel(searchResults);
        controller.setSearchResultsTableModel(searchResultTableModel);
    }
    /**
     * Create a new search with a given query
     * @param query
     * the query given
     */
    public void search(String query){
        searchResults = new SearchResults(this);
        searchResultTableModel = new SearchResultTableModel(searchResults);
        controller.setSearchResultsTableModel(searchResultTableModel);
        Search search = new Search(query, searchResults);
        search.start();
    }
    /**
     * Get the current SearchResults
     * @return the current SearchResults
     */
    public SearchResults getSearchResults(){
        return searchResults;
    }
    /**
     * A pass-through call that calls the controller.
     * @param searchResultTableModel
     */
    public void setSearchResultsTableModel(SearchResultTableModel searchResultTableModel){
        controller.setSearchResultsTableModel(searchResultTableModel);
    }
    /**
     * A pass-through call that calls the controller.
     */
    public void updateSearchResultsTable(){
        controller.updateSearchResultsTable();
    }
}
